package com.jic.veteran.portal.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.jic.veteran.common.api.CommonPage;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.model.ProjectMessage;
import com.jic.veteran.portal.domain.CaptchaDto;
import com.jic.veteran.portal.domain.ProjectMessageAddDto;
import com.jic.veteran.portal.domain.ProjectMessageListDto;
import com.jic.veteran.portal.service.CaptchaService;
import com.jic.veteran.portal.service.ProjectMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = "ProjectMessageController")
@Controller
@RequestMapping("/mesage")
public class ProjectMessageController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ProjectMessageController.class);
//
//    @Autowired
//    private ProjectMessageService projectMessageService;
//
//    @Autowired private CaptchaService captchaService;
//
//    @ApiOperation("根据项目编号获取留言列表")
//    @RequestMapping(value = "/list", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult<CommonPage<ProjectMessageListDto>> list(@RequestParam(value = "projectId", required = false) String projectId,
//                                                                @RequestParam(value = "pageSize", defaultValue = "100") Integer pageSize,
//                                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
//        List<ProjectMessageListDto> projectMessageList = projectMessageService.list(projectId, pageSize, pageNum);
//        return CommonResult.success(CommonPage.restPage(projectMessageList));
//    }
//
//    @ApiOperation("我的留言列表")
//    @RequestMapping(value = "/myList/{openid}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult<CommonPage<ProjectMessage>> myList(@PathVariable(value = "openid") String openid,
//                                                         @RequestParam(value = "pageSize", defaultValue = "100") Integer pageSize,
//                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
//        List<ProjectMessage> projectMessageList = projectMessageService.myList(openid, pageSize, pageNum);
//        return CommonResult.success(CommonPage.restPage(projectMessageList));
//    }
//
//    @ApiOperation("新增项目留言")
//    @RequestMapping(value = "/add/{projectId}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult add(@PathVariable String projectId,
//                            @RequestBody ProjectMessageAddDto projectMessage) {
//      CaptchaDto captcha = projectMessage.getCaptcha();
//      boolean verifyCaptchaResult = captchaService.verifyCaptcha(captcha);
//      if (!verifyCaptchaResult) {
//        return CommonResult.failed("验证码输入错误");
//      }
//      if (ObjectUtil.isEmpty(projectMessage)
//          || StrUtil.isBlank(projectMessage.getProjectMessage())) {
//        return CommonResult.failed("留言信息不能为空");
//      }
//        int count = projectMessageService.create(projectId,projectMessage);
//        if (count > 0) {
//            return CommonResult.success(count);
//        } else {
//            return CommonResult.failed();
//        }
//    }
//
//    @ApiOperation("修改项目留言")
//    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult update(@PathVariable Long id,
//                               @RequestBody ProjectMessage projectMessage) {
//        int count = projectMessageService.update(id,projectMessage);
//        if (count > 0) {
//            return CommonResult.success(count);
//        } else {
//            return CommonResult.failed();
//        }
//    }
//
//    @ApiOperation("根据ID获取留言详情")
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<ProjectMessage> getItem(@PathVariable Long id) {
//        ProjectMessage projectMessage = projectMessageService.getItem(id);
//        return CommonResult.success(projectMessage);
//    }
//
//    @ApiOperation("根据ID删除留言信息")
//    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult delete(@PathVariable Long id) {
//        int count = projectMessageService.delete(id);
//        if (count > 0) {
//            return CommonResult.success(count);
//        } else {
//            return CommonResult.failed();
//        }
//    }
}
